<?php
class Ultility
{		
	public static function StdString($vString)
	{
		$vString=str_replace(array(" and "),"&",$vString);
		$vString=str_replace(array(" sharp "),"#",$vString);
		$vString=str_replace(array(" source "),"\\\\",$vString);
		return $vString;
	} 
	public static function MySubString($vString,$vMax)
	{
		if(strlen($vString)<=$vMax) return $vString;
		$st=substr($vString,0,$vMax);
		while($st[strlen($st)-1]!=' ') //TRONG KHI KÝ TỰ CUỐI != ' ' THÌ CẮT 1 KÝ TỰ Ở CUỖI
		{
			$st=substr($st,0,strlen($st)-1);
		}
		if(strlen($st)<strlen($vString)) // NẾU CHUỖI ĐƯỢC CẮT NHỎ HƠN CHUỖI BĐ THÌ THÊM '...' 
		return $st.'...';
		else return $st;
	}
	public static function MyDate($vString)
	{
		return substr($vString,8,2).'/'.substr($vString,5,2).'/'.substr($vString,0,4);
	}
	public static function MyNumBer($vString)
	{
		/*$res='';
		$segment=strlen($vString)%3==0?strlen($vString)/3:(strlen($vString)/3+1);
		if(strlen($vString)%3==0)
		{			
			for($i=0;$i<$segment;++$i)
			{
				$res.=substr($vString,$i*3,3).',';
			}
			$res=substr($res,0,strlen($res)-1);
		}
		else
		{
			for($i=0;$i<$segment;++$i)
			{
				$res.=substr($vString,($i-1)*3+(strlen($vString)%3)>0?($i-1)*3+(strlen($vString)%3):0,($i-1)*3+(strlen($vString)%3)>0?3:(strlen($vString)%3)).',';
			}
			$res=substr($res,0,strlen($res)-2);
		}
		return $res;*/
		$vString = number_format($vString,2,',','.');
		if( substr($vString,strlen($vString)-2,2)=='00')$vString=substr($vString,0,strlen($vString)-3);
		return $vString;
	}
	public static function MyUnSlashString($vString)
	{
		return str_replace('\'\'','"',stripslashes($vString));
	}
	public static function MySlashString($vString)
	{
		//return addslashes($vString);
		return str_replace('"','\'\'',$vString);
	}
	public static function MyUnStdString($vString)
	{
		if($vString=='') return '';
		$vString=str_replace('\\',' source ',$vString);
		$vString=str_replace('#',' sharp ',$vString);
		return str_replace('&',' and ',$vString);
	}
	public static function MyUnSignString($vString)
	{
		$coDau=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă","ằ","ắ"
		,"ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề","ế","ệ","ể","ễ","ì","í","ị","ỉ","ĩ",
		"ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ"
		,"ờ","ớ","ợ","ở","ỡ",
		"ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
		"ỳ","ý","ỵ","ỷ","ỹ",
		"đ",
		"À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă"
		,"Ằ","Ắ","Ặ","Ẳ","Ẵ",
		"È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
		"Ì","Í","Ị","Ỉ","Ĩ",
		"Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ"
		,"Ờ","Ớ","Ợ","Ở","Ỡ",
		"Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
		"Ỳ","Ý","Ỵ","Ỷ","Ỹ",
		"Đ","ê","ù","à",
		"\\","/","!","@","#","$","%","^","&","*","(",")","-","_","+","=","[","{","]","}","\"","\'",":",";","<",",",">","?");
		$khongDau=array("a","a","a","a","a","a","a","a","a","a","a"
		,"a","a","a","a","a","a",
		"e","e","e","e","e","e","e","e","e","e","e",
		"i","i","i","i","i",
		"o","o","o","o","o","o","o","o","o","o","o","o"
		,"o","o","o","o","o",
		"u","u","u","u","u","u","u","u","u","u","u",
		"y","y","y","y","y",
		"d",
		"A","A","A","A","A","A","A","A","A","A","A","A"
		,"A","A","A","A","A",
		"E","E","E","E","E","E","E","E","E","E","E",
		"I","I","I","I","I",
		"O","O","O","O","O","O","O","O","O","O","O","O"
		,"O","O","O","O","O",
		"U","U","U","U","U","U","U","U","U","U","U",
		"Y","Y","Y","Y","Y",
		"D","e","u","a",
		" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ");
		$vString = str_replace($coDau,$khongDau,$vString);
		$vString = str_replace('  ',' ',$vString);
		return str_replace(' ','-',$vString);
	}
	
	public static function ConvertCuteDate($vString)
	{
		return substr($vString,8,2).'/'.substr($vString,5,2).'/'.substr($vString,0,4);
	}
	
	public static function ConvertFullTime($vString)
	{
		return substr($vString,8,2).'/'.substr($vString,5,2).'/'.substr($vString,0,4).' lúc '.substr($vString,11,8);
	}
	
}
?>